package com.wenhui.nzapp.ui.activity.dinnerqr;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gzwh.weblib.bean.NzDinnerRegion;
import com.gzwh.weblib.bean.Result;
import com.gzwh.weblib.utils.MyObserver;
import com.gzwh.weblib.utils.RequestUtils;
import com.wenhui.nzapp.R;
import com.wenhui.nzapp.ui.adapter.DinnerQrAreAdapter;
import com.wenhui.nzapp.ui.adapter.DinnerQrAreManagerAdapter;
import com.wenhuitec.sysui.TitleBuilder;

import java.util.List;

public class DinnerQrAreActivity extends AppCompatActivity {
    private Context mContext;

    private RecyclerView cateRv;

    private DinnerQrAreManagerAdapter dinnerQrAreManagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dinnerqr_are);
        mContext = this;
        new TitleBuilder(this)
                .setTitleText("点餐区域管理")
//                .setLeftIco(R.drawable.yp)
                .setLeftIcoListening((view) -> finish());
        cateRv = findViewById(R.id.cateRv);
        findViewById(R.id.addCategory).setOnClickListener(view -> {
            startActivity(new Intent(mContext, DinnerQrAreEditActivity.class));
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        RequestUtils.getAreList(mContext, new MyObserver<List<NzDinnerRegion>>(mContext, false) {
            @Override
            public void onSuccess(Result<List<NzDinnerRegion>> result) {
                System.out.println(result.toString());
                cateRv.setLayoutManager(new LinearLayoutManager(mContext));//设置布局管理器
                dinnerQrAreManagerAdapter = new DinnerQrAreManagerAdapter(mContext, result.getResult(), (nzDinnerRegion -> {
                    DinnerQrAreEditActivity.startAct(mContext, nzDinnerRegion);
                }));
                cateRv.setAdapter(dinnerQrAreManagerAdapter);

            }

            @Override
            public void onFailure(Throwable e, String errorMsg) {

            }
        });
    }
}
